using NUnit.Framework;
using ValidationFramework.Configuration;
using ValidationFramework.Extensions;
using ValidationFramework.Reflection;

namespace ValidationFramework.Tests
{
    [TestFixture]
    public class LengthStringRuleConfigReaderTest
    {

        #region Methods

      [Test]
      public void ReadConfig()
      {
          const string validatorXml = "<rule errorMessage='hello' typeName='LengthStringRule' ruleSet='foo' minimum='1' maximum='5' trimWhiteSpace='false'/>";
          var ruleData = (RuleData.Read(validatorXml.ToXmlReader()));
		var rule = (LengthStringRule)ConfigurationService.GetRule(ruleData, TypePointers.StringTypeHandle);
        Assert.AreEqual("hello", rule.ErrorMessage);
        Assert.AreEqual(1, rule.Minimum);
        Assert.AreEqual(5, rule.Maximum);
        Assert.IsFalse(rule.TrimWhiteSpace);

      }

      [Test]
      public void ReadConfigNoMinimum()
      {
          const string validatorXml = "<rule typeName='LengthStringRule' maximum='5'/>";
          var ruleData = (RuleData.Read(validatorXml.ToXmlReader()));
		var rule = (LengthStringRule)ConfigurationService.GetRule(ruleData, TypePointers.StringTypeHandle);
        Assert.AreEqual(null, rule.ErrorMessage);
        Assert.AreEqual(0, rule.Minimum);
        Assert.AreEqual(5, rule.Maximum);
        Assert.IsTrue(rule.TrimWhiteSpace);

      }

        #endregion


    }
}